package com.example.chinawenddingexpo.repository;

import com.example.chinawenddingexpo.model.EventBooking;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

@Repository
public interface EventBookingRepository extends JpaRepository<EventBooking, Long> {
    
    List<EventBooking> findByUserIdOrderByBookingTimeDesc(Long userId);
    
    List<EventBooking> findByEventIdOrderByBookingTimeDesc(Long eventId);
    
    List<EventBooking> findByUserIdAndStatusOrderByBookingTimeDesc(Long userId, EventBooking.BookingStatus status);
    
    @Query("SELECT eb FROM EventBooking eb WHERE eb.event.id = :eventId AND eb.status = 'CONFIRMED'")
    List<EventBooking> findConfirmedBookingsByEvent(@Param("eventId") Long eventId);
    
    EventBooking findByBookingCode(String bookingCode);
    
    @Query("SELECT eb FROM EventBooking eb WHERE eb.event.startTime > :now AND eb.status = 'CONFIRMED' ORDER BY eb.event.startTime ASC")
    List<EventBooking> findUpcomingBookings(@Param("now") LocalDateTime now);
}